<?php $this->load->view(TEMPLATE_NAME.'/admin/header');?>

<?php $this->load->view(TEMPLATE_NAME.'/admin/side_left');?>

<link rel="stylesheet" type="text/css" media="all" href="<?php echo base_url()?>xhtml/admin/css/tia.css" />

<script type="text/javascript" src="<?php echo base_url()?>js/jquery-1.4.2.js"></script>

<script type="text/javascript" src="<?php echo base_url()?>js/jquery.validate.pack.js"></script>

<script src="<?php echo base_url(); ?>js/ajaxfileupload.js"></script>

<script src="<?php echo base_url(); ?>js/si.files.js"></script>

<style type="text/css" title="text/css">

.SI-FILES-STYLIZED label.cabinet

{

    width: 100px;

    height: 28px;

    background: url(<?php echo base_url()?>image/select_news.jpg) 0 0 no-repeat;

    display: block;

    overflow: hidden;

    cursor: pointer;

}



.SI-FILES-STYLIZED label.cabinet input.file

{

    position: relative;

    height: 100%;

    width: auto;

    opacity: 0;

    -moz-opacity: 0;

    filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);

}

</style>

<script type="text/javascript">

SI.Files.stylizeAll();

$(document).ready(function(){

    var i = 2;

    $('#add_more').click(function(){      

        $('#add_image').append('<div class="labelf"><br /><strong class="purple">Image '+i+':</strong><br /><br /><br />Caption: <br />'

            + '<span class="purple">(optional)</span></div><div class="fotor" style="position: relative"><div class="select_label">'

            <?php if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)):?>

            + '<input name="file_'+i+'" class="file" type="file" id="file_'+i+'" onchange="return ajaxFileUpload(this);"/>'

            <?php else:  ?>

            + ' <label class="cabinet">'

            + '<input name="file_'+i+'" class="file" type="file" id="file_'+i+'" onchange="return ajaxFileUpload(this);"/>'

            + '</label>'

            <?php endif;?>

            + '</div><div style="position:relative;float:left"><img id="loading_'+i+'" src="<?php echo base_url()?>image/loading_blue.gif" style="display:none;position:absolute;z-index:1000;left:0px;top:0px" />'

            + '</div><div id="img_'+i+'" class="select_image" ">'

            + '<!--<img src="<?php echo base_url()?>xhtml/img/blank3.gif" width="75" height="75">--></div>'

            + '<div class="select_textarea"><textarea name="news_caption[]"></textarea></div>'

        );

        i++;

        return false;    

    });        

});



function show_edit(idm){

    var edit = '#edit_' + idm;

    $(edit).slideToggle("slow"); 

    return false;   

}

// ajax upload

function ajaxFileUpload(get_this){

    var this_id = get_this.id.split('_');

    

    if(this_id[1]){

        var div_load = "#loading_" + this_id[1];     

        $(div_load)

        .ajaxStart(function(){

            $(this).show();

        })

        .ajaxComplete(function(){

            $(this).hide();

            $(this).unbind("ajaxStart");

        })    

        .ajaxStop(function(){

            $(this).unbind("ajaxComplete");    

        });

            

        var img = '#img_' + this_id[1];

        $.ajaxFileUpload({

            url:"<?php echo site_url('ajax_upload/upload_directory_image/upload/photo/network')?>/<?php echo $company['company_slug_name']?>/file/"+get_this.id,

            secureuri:false,       

            fileElementId: get_this.id,

            dataType: 'json',

            success: function (data, status){

                if(typeof(data.error) != 'undefined'){

                    if(data.error != ''){                    

                        $(img).html(data.error);

                    }else{                        

                        $(img).html('<img src="<?php echo base_url();?>uploads/directory/photo/thumb/'+data.msg+'" width="75" /><br />'

                        +'<input type="hidden" name="upload[]" value="'+data.msg +'"><br />'

                        +'<input type="hidden" name="upload_ori[]" value="'+data.ori +'">');

                    }

                }

            },

            error: function (data, status, e){

                $(img).html(e);

            }

        });

    

    }else{

        var this_id = get_this.id.split('-');

        var div_load = "#loading-" + this_id[1];

     

        $(div_load)

        .ajaxStart(function(){

            $(div_load).show();

        })

        .ajaxComplete(function(){

            $(div_load).hide();

            $(this).unbind("ajaxStart");

        })

        .ajaxStop(function(){

            $(this).unbind("ajaxComplete");    

        });    

        

        var img = '#img-' + this_id[1];

        $.ajaxFileUpload({            

            url:"<?php echo site_url('ajax_upload/upload_directory_image/upload/photo/network')?>/<?php echo $company['company_slug_name']?>/file/"+get_this.id,

            secureuri:false,       

            fileElementId: get_this.id,

            dataType: 'json',

            success: function (data, status){
               
                if(typeof(data.error) != 'undefined'){

                    if(data.error != ''){                    

                        $(img).html(data.error);

                    }else{

                        $(img).html('<img src="<?php echo base_url();?>uploads/directory/photo/thumb/'+data.msg+'" width="75" /><br />'                                               

                        +'<input id="upload-' + this_id[1] +'" type="hidden" value="'+data.msg +'"><br />'

                        +'<input type="hidden" id="upload_ori-'+ this_id[1] +'" value="'+data.ori +'">');

                    }

                }

            },

            error: function (data, status, e){

                $(img).html(e);

            }

        });  

    }    

}



function update_gallery(idp){

    var temp_capt = '#upload-image-caption-' + idp;

    var temp_file = '#upload-' + idp;

    var temp_gallery = '#gallery_' + idp;

    var temp_edit = '#edit_' + idp;

    var temp_ori = '#upload_ori-' + idp;

    

    $.post('<?php echo site_url("json_request/update_directory_photo/")?>' ,{

         id : idp,

         file : $(temp_file).val(),

         caption : $(temp_capt).val(),

         ori: $(temp_ori).val()                                  

    },function(data){  

        $(temp_gallery).html('<a class="edit" onclick="show_edit('+data.id+')" >edit</a>'

        +'<img src="<?php echo base_url();?>uploads/directory/photo/thumb/'+data.file+'" width="75" />'        

        +'<input type="checkbox" name="photo_id[]" value="'+data.id+'">'

        +'<p>'+data.caption+'</p>');

        $(temp_edit).slideUp();        

    }, "json");    

}

</script>

<div class="page noright adminpage">

<h5 class="purple">The Mykprisguide Print - Design Directory</h5>

<hr />

<?php $this->load->view(TEMPLATE_NAME.'/admin/directory/directory_admin_header');?>

<hr />

<?php $this->load->view(TEMPLATE_NAME.'/admin/directory/directory_admin_editlisting_header');?> 

<hr />



<div class="wright">

<p class="f15 purple">Photo Gallery</p>

<hr />

<?php if(!empty($notification)){ ?>

<p class="inform f12 error_message"><?php echo $notification ?></p><hr />

<?php } ?>

<?php 

$action = 'admin/design_directory/photo/id/'.$company['id'];

if(!empty($company_photo)){

    ?>

<?php 

echo form_open($action)?>

<?php foreach($company_photo as $photo){?>

<div class="fotolist">

    <div id="gallery_<?php echo $photo['id'] ?>">

        <a class="edit" style="cursor:pointer" onclick="show_edit('<?php echo $photo['id'] ?>')" >edit</a>

        <?php if(!empty($photo['image'])){?>

        <img src="<?php echo base_url();?>uploads/directory/photo/thumb/<?php echo $photo['image']?>" width="75" />

        <?php }else{?>

        <img src="<?php echo base_url()?>xhtml/img/blank3.gif" width="75" height="75" />

        <?php } ?>

        <input type="checkbox" name="photo_id[]" value="<?php echo $photo['id']?>">

        <p><?php echo $photo['caption']?></p>

    </div>

    <div class="clear"></div>

    <!-- Edit photo start -->

    <div id="edit_<?php echo $photo['id'] ?>" style="display:none" class="addfoto">

        <hr />    

        <div class="labelf purple1">

            <br>

            <strong class="purple1">Image :</strong>

            <br><br><br>

            Caption: <br>

            <span class="purple1">(optional)</span>

        </div><!-- labelf -->

        <div class="fotor" style="position: relative">            

            <!-- ie show button -->

            <?php if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)):?>

                <input name="file-<?php echo $photo['id']?>" class="file" type="file" id="file-<?php echo $photo['id']?>" onchange="return ajaxFileUpload(this);"/>

            <?php else:  ?>

                <div class="select_label"><label class="cabinet"> 

                    <input name="file-<?php echo $photo['id']?>" class="file" type="file" id="file-<?php echo $photo['id']?>" onchange="return ajaxFileUpload(this);"/>

                </label>
</div>
            <?php endif;?> 

            <div style="position:relative; float:left;"><img id="loading-<?php echo $photo['id']?>" src="<?php echo base_url()?>image/loading_blue.gif" style="display:none;position:absolute;z-index:1000;left:20px;top:50px" /></div>

            <div id="img-<?php echo $photo['id']?>" class="select_image"> 

                <img src="<?php echo base_url();?>uploads/directory/photo/thumb/<?php echo $photo['image']?>" width="75" />

                <input type="hidden" id="upload-<?php echo $photo['id'] ?>" value="<?php echo $photo['image'];?>">

                <input type="hidden" id="upload_ori-<?php echo $photo['id'] ?>" value="<?php echo $photo['original'];?>">             

            </div>
<div class="select_textarea">
            <textarea id="upload-image-caption-<?php echo $photo['id'] ?>" name="news_caption[]"><?php echo $photo['caption']?></textarea></div>

            <button onclick="update_gallery('<?php echo $photo['id'] ?>');return false;">Update</button>  

        </div><!-- fotor -->    

    </div>

    <!-- Edit photo end -->    

    <div class="clear"></div>

</div><!-- fotolist -->

<hr />

<?php } // end foreach

$form_button = array(

    'type'=>'submit',

    'name'=>'submit',

    'value'=>'delete',

    'class' => 'nolabel',

    'content'=>'DELETE SELECTED',

);

echo form_button($form_button); 

echo form_close();?>

<hr>

<?php } // end if ?>

<h4 class="f17" style="font-size:17px">add photos to this gallery</h4><br />

<?php 

echo form_open_multipart($action)?>

<div class="addfoto">    

    <div class="labelf purple1">

        <br>

        <strong class="purple1">Image 1:</strong>

        <br><br><br>

        Caption: <br>

        <span class="purple1">(optional)</span>

    </div><!-- labelf -->

    <div class="fotor" style="position: relative">       

        <!-- ie show button -->

        <div class="select_label"><?php if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)):?>

            <input name="file_1" class="file" type="file" id="file_1" onchange="return ajaxFileUpload(this);"/>

        <?php else:  ?>

            <label class="cabinet"> 

                <input name="file_1" class="file" type="file" id="file_1" onchange="return ajaxFileUpload(this);"/>

            </label>

        <?php endif;?> 

        </div>

        <div style="position:relative; float:left">

        <img id="loading_1" src="<?php echo base_url()?>image/loading_blue.gif" style="display:none;position:absolute;z-index:1000;left:0px;top:0px" />

        </div>

        

        <div id="img_1"class="select_image"> 

            <!--<img src="<?php// echo base_url()?>xhtml/img/blank3.gif" width="75" height="75"> -->            

        </div>

        

        <div class="select_textarea"><textarea name="news_caption[]"></textarea></div>

    </div><!-- fotor -->

<div class="clear"></div>

<div id="add_image"></div>

</div><!-- addfoto -->

<div class="addfoto">

    <div class="labelf">&nbsp;</div><!-- labelf -->

    <div class="fotor"><strong><a id="add_more" href="">+ add another image</a></strong> <br /><br />

    <?php 

            $form_button = array(

                'type'=>'submit',

                'name'=>'submit',

                'value'=>'submit',

                'content'=>'Submit',

            );

            echo form_button($form_button) ?>

    </div><!-- fotor --> 

    <div class="clear"></div>       

</div><!-- addfoto -->

<?php echo form_close(); ?>

</div><!-- wright -->



</div><!-- page -->

<?php $this->load->view(TEMPLATE_NAME.'/admin/footer');?>